@miso.ai/doggoganger 0.9.1-beta.12 → 0.9.1-beta.13

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1 +1 @@
1
- !function(t,e){"object"==typeof exports&&"undefined"!=typeof module?module.exports=e():"function"==typeof define&&define.amd?define(e):(t="undefined"!=typeof globalThis?globalThis:t||self).doggoganger=e()}(this,(function(){"use strict";function t(){return"10000000-1000-4000-8000-100000000000".replace(/[018]/g,(t=>(t^16*Math.random()>>t/4).toString(16)))}function e(t,e){return null!=e&&e>t?t+Math.floor(Math.random()*(e-t)):t}function n(t,n){const r=e(...n),o=[];for(let e=0;r>e;e++)o.push(t());return o}function r(){return Math.random().toString(36).substring(2,10)}function o(t){for(let e=t.length-1;e>0;e--){const n=Math.floor(Math.random()*(e+1));[t[e],t[n]]=[t[n],t[e]]}return t}function s(t){return`https://picsum.photos/seed/${Math.floor(1e3*Math.random())}/${Array.isArray(t)?t.length>1?`${t[0]}/${t[1]}`:""+t[0]:""+t}`}function i(t){const e=new Date(t).toISOString();return e.endsWith("Z")?e.slice(0,-1):e}function a(t,e){return void 0!==e?Math.ceil(t*e):t}function u(){return c()+c()+c()}function c(){return 2*Math.random()-1}var l=Object.freeze({__proto__:null,formatDatetime:i,gaussRandom:u,id:r,imageUrl:s,randomInt:e,repeat:n,sample:a,shuffle:o,uuid:t}),f=["lorem","ipsum","dolor","sit","amet","consectetur","adipiscing","elit","curabitur","vel","hendrerit","libero","eleifend","blandit","nunc","ornare","odio","ut","orci","gravida","imperdiet","nullam","purus","lacinia","a","pretium","quis","congue","praesent","sagittis","laoreet","auctor","mauris","non","velit","eros","dictum","proin","accumsan","sapien","nec","massa","volutpat","venenatis","sed","eu","molestie","lacus","quisque","porttitor","ligula","dui","mollis","tempus","at","magna","vestibulum","turpis","ac","diam","tincidunt","id","condimentum","enim","sodales","in","hac","habitasse","platea","dictumst","aenean","neque","fusce","augue","leo","eget","semper","mattis","tortor","scelerisque","nulla","interdum","tellus","malesuada","rhoncus","porta","sem","aliquet","et","nam","suspendisse","potenti","vivamus","luctus","fringilla","erat","donec","justo","vehicula","ultricies","varius","ante","primis","faucibus","ultrices","posuere","cubilia","curae","etiam","cursus","aliquam","quam","dapibus","nisl","feugiat","egestas","class","aptent","taciti","sociosqu","ad","litora","torquent","per","conubia","nostra","inceptos","himenaeos","phasellus","nibh","pulvinar","vitae","urna","iaculis","lobortis","nisi","viverra","arcu","morbi","pellentesque","metus","commodo","ut","facilisis","felis","tristique","ullamcorper","placerat","aenean","convallis","sollicitudin","integer","rutrum","duis","est","etiam","bibendum","donec","pharetra","vulputate","maecenas","mi","fermentum","consequat","suscipit","aliquam","habitant","senectus","netus","fames","quisque","euismod","curabitur","lectus","elementum","tempor","risus","cras"];function d({decorates:t=[],output:e="string",size:n,min:r,max:o,...s}={}){let i=b(n||[r,o])(h(s));for(const e of t)i=m(e)(i);return m(e)(i)}const p={string:g,array:_,title:y,description:v,multiline:w};function m(t){switch(typeof t){case"string":return p[t]();case"function":return t;case"object":if(Array.isArray(t)){const[e,n={}]=t;return p[e](n)}}throw Error("Unrecognized decorator/output form: "+t)}function*h({words:t=f,fixedStarts:e=0}={}){const n=t.length;for(let r=0;;r++)yield t[e>r?r:Math.floor(Math.random()*n)]}function g({separator:t=" "}={}){return e=>[...e].join(t)}function _(){return t=>[...t]}function w({wordsPerLine:t={avg:10,std:3,min:1}}={}){return e=>{let n=q(t),r="";for(let o of e)r&&(0==n--?(r+="\n",n=q(t)):r+=" "),r+=o;return r}}function b(t=[5,10]){const n="number"==typeof t?t:e(...t);return function*(t){let e=0;for(let r of t){if(e++>=n)break;yield r}}}function y({}={}){return function*(t){for(let e of t)yield z(e)}}function v({wordsPerSentence:t={avg:24,std:5,min:1},punctuation:e="."}={}){return function*(n){let r,o=0;for(let s of n)r&&(yield r),r=s,0===o&&(r=z(r),o=q(t)),0==--o&&(r+=e);r&&(r.endsWith(e)||(r+=e),yield r)}}function z(t){return t[0].toUpperCase()+t.substring(1)}function q(t){if("number"==typeof t)return Math.round(e);let{avg:e,std:n,min:r,max:o}=t;void 0===n&&(n=e/4);let s=u()*n+e;return void 0!==r&&(s=Math.max(r,s)),void 0!==o&&(s=Math.min(o,s)),Math.round(s)}var $=Object.freeze({__proto__:null,array:_,base:h,description:v,limit:b,lorem:d,multiline:w,string:g,title:y});const M="// module\nimport { a, b } from './module';\nimport * as module from './module';\nimport module from './module';\nexport default module;\nexport const a = 0;\nexport * from './module';\nexport * as module from './module';\n\n// variables\nlet a = 10;\nconst b = 20;\n\n// function declaration\nfunction sum(x, y) {\n return x + y;\n}\n\n// generator function\nfunction* iterator() {\n yield 0;\n yield 1;\n}\n\n// arrow function\nconst multiply = (x, y) => x * y;\n\n// class\nclass Person {\n constructor(name, age) {\n this.name = name;\n this.age = age;\n }\n\n greet() {\n console.log('Hello, my name is Miso.');\n }\n}\n\n// primitive\nconst str = 'Hello, world!';\nconst num = 10.99;\n\n// object\nconst person = new Person('John', 30);\nperson.greet();\n\n// object literal\nconst object = {\n name: 'John',\n [x]: 10,\n ...props,\n};\n\n// array literal\nconst arr = [1, 2, 3, 4, 5, ...props];\n\n// regexp literal\nconst regexp = /\\w+/g;\n\n// operators\nconst sum = a + b;\nconst product = a * b;\nconst negation = -a;\nconst max = a > b ? a : b;\n\n// flow control\nlet i = 9;\nfor (const n of arr) {\n if (n > i) {\n console.log(n);\n }\n i++;\n}\n\n// async/await\n(async () => {\n const result = await asyncFunction();\n})();\n\n// try/catch\ntry {\n} catch (e) {\n}\n\n// destructuring\nconst { name, age, ...rest } = person;\nconst [ x, y, ...rest ] = arr;\n\n// template literals\nconsole.log(`The sum of ${a} and ${b} is ${sum(a, b)}.`);";var x=Object.freeze({__proto__:null,javascript:function(){return M},js:function(){return M}});function j({features:t,blocks:e=[8,12],sampling:n=1}={}){let r=[];return[r,t]=function(t=[]){const e=new Set,n=[];for(const r of t)if(r.startsWith("lang-")){let t=r.slice(5);"javascript"===t&&(t="js"),e.add(t)}else n.push(r);return[[...e],n]}(t),function(t,e){const n=[];for(const r of t)1>e&&Math.random()>=e||n.push(r());return n}([()=>S({features:t}),()=>A({features:t}),...r.map((e=>()=>O({lang:e,features:t}))),...r.length?[]:[()=>O({features:t})],()=>A({features:t}),()=>C({features:t}),()=>D(),()=>A({features:t}),()=>k(),()=>S({features:t}),()=>A({features:t}),()=>F({features:t}),()=>A({features:t})],n).join("\n\n")}function k(){return"*-_".charAt(e(0,2)).repeat(e(3,6))}function S({level:t=[1,6],size:n=[1,8],content:r}){const o=r||d({size:n});return`${"#".repeat(e(...t))} ${o}`}function O({lang:t,content:n,size:r,fenceChar:o="`"}){return"random"===o&&(o="`~".charAt(e(0,1))),n=n||B({lang:t,size:r}),`${o.repeat(3)}${t||""}\n${n}\n${o.repeat(3)}`}function A({size:t=[20,50]}){return d({size:t,decorates:["description",U()]})}function C({columns:t=[2,4],rows:n=[2,8]}){t=e(...t),n=e(...n);const r=[...K({size:1},t-1),{size:[3,8]}],o=[d({size:t,output:"array"}),r.map((()=>"---"))];for(let t=0;n-1>t;t++)o.push(r.map((({size:t})=>d({size:t}))));return o.map(J).join("\n")}function D({url:t,imageSize:e=[400,250],...n}={}){return t=t||s(e),`![${E(n)}](${t})`}const T=["ordered","bullet","task"];function F({features:t,type:n="random",count:r=[1,8],size:o=[5,15]}){r="number"==typeof r?r:e(...r);const s="random"===n?T[Math.floor(3*Math.random())]:n,i=[];for(;r>0;){const a=e(1,r);let u=A({features:t,size:o});a>1&&(u+="\n"+F({features:t,type:n,count:a-1,size:o})),i.push(W(s,u)),r-=a}return i.join("\n")}const H={"code-span":()=>["`","`"],"emphasis-1":()=>K(I(1),2),"emphasis-2":()=>K(I(2),2),"emphasis-3":()=>K(I(3),2),strikethrough:()=>["~","~"],link:({url:t="https://miso.ai"}={})=>["[",`](${t})`]};function I(t=[1,3]){return t="number"==typeof t?t:e(...t),"_*".charAt(e(0,1)).repeat(t)}const L=Object.keys(H),P=new Set(L);function U({features:t=L,size:n=[1,3],rest:r=[0,8]}={}){t=t.filter((t=>P.has(t)));const s=o([...t]);let i=s.length-1;const a=()=>"number"==typeof r?r:e(...r);return function*(r){let o,u,c=a();for(const l of r)if(u&&(yield u),0===c)if(o)u=`${l}${o}`,o=void 0,c=a();else{const[r,a]=H[0>i?t[e(0,t.length-1)]:s[i--]]();u=`${r}${l}`,o=a,c="number"==typeof n?n:e(...n)}else u=l,c--;u&&(yield void 0!==o?`${u}${o}`:u)}}function E({size:t=[1,3],content:e}={}){return e||d({size:t})}function R(t,e){return e.split("\n").map((e=>" ".repeat(t)+e)).join("\n")}function W(t,e){const[n,r]=e.split("\n",2),o=`${function(t,e="random"){switch(t){case"ordered":return"1.";case"bullet":return"-";case"task":return`- [${("random"===e?.5>Math.random():e)?"x":" "}]`;default:throw Error("unknown list item type: "+t)}}(t)} ${n}`;return r?o+"\n"+R("ordered"===t?3:2,r):o}function B({lang:t,size:e=[10,30]}){return t&&x[t]?x[t]():d({output:"multiline",size:e})}function J(t){return`| ${t.join(" | ")} |`}function K(t,e){const n=[];for(let r=0;e>r;r++)n.push("function"==typeof t?t():t);return n}var G=Object.freeze({__proto__:null,atxHeading:S,blockquote:function({size:t=[3,5]}){return d({size:t}).split("\n").map((t=>"> "+t)).join("\n")},codeSpan:function(t){return`\`${E(t)}\``},decorate:U,emphasis:function({level:t=[1,3],options:n}){t="number"==typeof t?t:e(...t);const r="_*".charAt(e(0,1)).repeat(t);return`${r}${E(n)}${r}`},fencedCodeBlock:O,hr:k,image:D,indent:R,indentedCodeBlock:function({lang:t,content:e,size:n}){return R(4,e=e||B({lang:t,size:n}))},link:function({url:t="https://miso.ai",...e}={}){return`[${E(e)}](${t})`},linkReferenceDefinition:function({label:t,destination:e,title:n}){return`[${t}]: ${e}${void 0!==n?" "+n:""}`},list:F,listItem:W,markdown:j,paragraph:A,setextHeading:function({level:t=[1,2],size:n=[1,8],content:r}){return`${r||d({size:n})}\n${"=-".charAt(e(...t)-1).repeat(3)}`},table:C});function N({size:t=300}={}){return s(t)}function Q({size:t=[1,3]}={}){return d({size:t,decorates:["title"],output:"array"})}function V({size:t=[1,4]}={}){return d({size:t,output:"array"})}function Z({size:t=[2,6]}={}){return d({size:t,decorates:["title"]})}function X({size:t=[10,20],...e}={}){return d({size:t,decorates:[Object.keys(e).length?["description",e]:"description"]})}function Y({paragraphs:t=8,sections:e,paragraph:n,image:r}={}){n={size:[30,60],...n},r={size:[480,270],...r},void 0===e&&(e=Math.floor(t*(1+Math.random())/4));const o=[],s=t/(e=Math.max(1,Math.min(e,t)));let i=0;for(let t=0;e>t;t++){for(t>0&&o.push(`<h4>${Z()}</h4>`);i++<(t+1)*s;)o.push(`<p>${X(n)}</p>`);o.push(`<div class="image-container"><img src="${N(r)}"></div>`)}return o.join("")}function tt(){return Math.random()>.3?"IN_STOCK":"OUT_OF_STOCK"}function et(){return Math.floor(1e4*Math.random())/100}function nt(){return Math.floor(500*Math.random())/100+1}function rt({format:t,sampling:e,features:n}){return"markdown"===t?j({sampling:e,features:n}):d({min:a(50,e),max:a(50,e),decorates:["description"]})}function*ot({rows:t,...e}={}){for(let n=0;t>n;n++)yield st({...e,index:n})}function st({}={}){const t=r(),e=n(et,[1,2]);return e.sort(),{product_id:t,authors:Q(),categories:[],tags:V(),title:Z(),description:X(),cover_image:N(),url:"https://dummy.miso.ai/products/"+t,sale_price:e[0],original_price:e[e.length-1],rating:nt(),availability:tt()}}function*it({rows:t,...e}={}){for(let n=0;t>n;n++)yield at({...e,index:n})}function at({html:t}={}){const e=r();return{product_id:e,authors:Q(),categories:[],tags:V(),title:Z({size:[4,10]}),snippet:X({size:[20,40]}),html:Y(t),cover_image:N(),url:"/products/"+e}}function*ut({rows:t=5,...e}={}){for(let n=0;t>n;n++)yield ct({...e,index:n})}function ct({}={}){return X({size:[4,8],punctuation:"?"})}function lt({question:e,parent_question_id:n,timestamp:r=Date.now()},{answerFormat:o="markdown",answerSampling:s,answerLanguages:a=[]}={}){const u=t(),c=i(r),l=void 0!==s?Math.max(0,Math.min(1,s)):void 0,f=rt({format:o,sampling:l,features:a.length?a.map((t=>"lang-"+t)):void 0}),d=[...it({rows:ft(6,8,l)})].map(dt);return{question:e,question_id:u,...n&&{parent_question_id:n},datetime:c,answer:f,sources:[...it({rows:ft(4,6,l)})].map(dt),related_resources:d,followup_questions:[...ut({rows:ft(3,6)})]}}function ft(t,n,r){return e(a(t,r),a(n,r))}function dt({html:t,...e}){return e}var pt=Object.freeze({__proto__:null,answer:lt,articles:it,fields:Object.freeze({__proto__:null,answer:rt,authors:Q,availability:tt,description:X,html:Y,image:N,price:et,rating:nt,tags:V,title:Z}),lorem:$,md:G,products:ot,questions:ut,utils:l});const mt=[{name:"fetch",duration:1.5,text:"Checking the question and fetching results... "},{name:"verify",duration:1.5,text:"Verifying results... "},{name:"generate",duration:1.5,text:"Generating answer... "}];class ht{constructor(t={}){this._options=t,this._answers=new Map}questions(t,e={}){const n=new gt(t,{...this._options,...e}),{question_id:r}=n;return this._answers.set(r,n),{question_id:r}}answer(t){const e=this._answers.get(t);if(!e){const e=Error("Question not found: "+t);throw e.status=404,e}return e.get()}related_questions(t){return{related_questions:[...ut(t)]}}}class gt{constructor({question:t,parent_question_id:e},{answerFormat:n,answerSampling:r,answerLanguages:o,...s}={}){this._options=Object.freeze(s);const i=this.timestamp=Date.now();this._data=lt({question:t,parent_question_id:e,timestamp:i},{answerFormat:n,answerSampling:r,answerLanguages:o})}get question_id(){return this._data.question_id}get(){const t=(Date.now()-this.timestamp)*(this._options.speedRate||1)/1e3,[e,n,r]=this._answer(t),o=this._sources(t,r),s=this._related_resources(t,r),i=this._followup_questions(t,r),{question_id:a,question:u,datetime:c,parent_question_id:l}=this._data;return{answer:n,answer_stage:e,datetime:c,finished:r,parent_question_id:l,question:u,question_id:a,sources:o,related_resources:s,followup_questions:i}}_answer(t){for(const e of mt)if(0>(t-=e.duration))return[e.name,e.text,!1];const{answer:e}=this._data,n=Math.floor(100*t),r=n>=e.length;return["result",r?e:e.slice(0,n),r]}_sources(t,e){const{sources:n}=this._data;if(e)return n;const{length:r}=n;return n.slice(0,Math.floor(r*t/3))}_related_resources(t,e){const{related_resources:n}=this._data;if(e)return n;const{length:r}=n;return n.slice(0,Math.floor(r*t/3))}_followup_questions(t,e){const{followup_questions:n}=this._data;if(e||!n)return n;const{length:r}=n;return n.slice(0,Math.floor(r*t/3))}}class _t{constructor(t){this._options=t}search({rows:t=5}){return{products:[...ot({rows:t})]}}}class wt{constructor(t){this._options=t}user_to_products({rows:t=5}){return{products:[...ot({rows:t})]}}product_to_products({rows:t=5}){return{products:[...ot({rows:t})]}}}class bt{constructor(t){this._options=t}upload(t){return[]}}class yt{constructor(t){this._options=t}upload(t){return[]}ids(){const t=[];for(let e=0;5e3>e;e++)t.push(vt(e));return{ids:t}}}function vt(t){return`${10>t?"p_000":100>t?"p_00":1e3>t?"p_0":"p_"}${t}`}class zt{constructor(t){this.ask=new ht(t),this.search=new _t(t),this.recommendation=new wt(t),this.interactions=new bt(t),this.products=new yt(t)}}return{buildApi:(...t)=>new zt(...t),data:pt}}));
1
+ !function(t,e){"object"==typeof exports&&"undefined"!=typeof module?module.exports=e():"function"==typeof define&&define.amd?define(e):(t="undefined"!=typeof globalThis?globalThis:t||self).doggoganger=e()}(this,(function(){"use strict";function t(){return"10000000-1000-4000-8000-100000000000".replace(/[018]/g,(t=>(t^16*Math.random()>>t/4).toString(16)))}function e(t,e){return null!=e&&e>t?t+Math.floor(Math.random()*(e-t)):t}function n(t,n){const r=e(...n),o=[];for(let e=0;r>e;e++)o.push(t());return o}function r(){return Math.random().toString(36).substring(2,10)}function o(t){for(let e=t.length-1;e>0;e--){const n=Math.floor(Math.random()*(e+1));[t[e],t[n]]=[t[n],t[e]]}return t}function s(t){return`https://picsum.photos/seed/${Math.floor(1e3*Math.random())}/${Array.isArray(t)?t.length>1?`${t[0]}/${t[1]}`:""+t[0]:""+t}`}function i(t){const e=new Date(t).toISOString();return e.endsWith("Z")?e.slice(0,-1):e}function a(t,e){return void 0!==e?Math.ceil(t*e):t}function u(){return c()+c()+c()}function c(){return 2*Math.random()-1}var l=Object.freeze({__proto__:null,formatDatetime:i,gaussRandom:u,id:r,imageUrl:s,randomInt:e,repeat:n,sample:a,shuffle:o,uuid:t}),f=["lorem","ipsum","dolor","sit","amet","consectetur","adipiscing","elit","curabitur","vel","hendrerit","libero","eleifend","blandit","nunc","ornare","odio","ut","orci","gravida","imperdiet","nullam","purus","lacinia","a","pretium","quis","congue","praesent","sagittis","laoreet","auctor","mauris","non","velit","eros","dictum","proin","accumsan","sapien","nec","massa","volutpat","venenatis","sed","eu","molestie","lacus","quisque","porttitor","ligula","dui","mollis","tempus","at","magna","vestibulum","turpis","ac","diam","tincidunt","id","condimentum","enim","sodales","in","hac","habitasse","platea","dictumst","aenean","neque","fusce","augue","leo","eget","semper","mattis","tortor","scelerisque","nulla","interdum","tellus","malesuada","rhoncus","porta","sem","aliquet","et","nam","suspendisse","potenti","vivamus","luctus","fringilla","erat","donec","justo","vehicula","ultricies","varius","ante","primis","faucibus","ultrices","posuere","cubilia","curae","etiam","cursus","aliquam","quam","dapibus","nisl","feugiat","egestas","class","aptent","taciti","sociosqu","ad","litora","torquent","per","conubia","nostra","inceptos","himenaeos","phasellus","nibh","pulvinar","vitae","urna","iaculis","lobortis","nisi","viverra","arcu","morbi","pellentesque","metus","commodo","ut","facilisis","felis","tristique","ullamcorper","placerat","aenean","convallis","sollicitudin","integer","rutrum","duis","est","etiam","bibendum","donec","pharetra","vulputate","maecenas","mi","fermentum","consequat","suscipit","aliquam","habitant","senectus","netus","fames","quisque","euismod","curabitur","lectus","elementum","tempor","risus","cras"];function d({decorates:t=[],output:e="string",size:n,min:r,max:o,...s}={}){let i=b(n||[r,o])(h(s));for(const e of t)i=p(e)(i);return p(e)(i)}const m={string:g,array:_,title:y,description:v,multiline:w};function p(t){switch(typeof t){case"string":return m[t]();case"function":return t;case"object":if(Array.isArray(t)){const[e,n={}]=t;return m[e](n)}}throw Error("Unrecognized decorator/output form: "+t)}function*h({words:t=f,fixedStarts:e=0}={}){const n=t.length;for(let r=0;;r++)yield t[e>r?r:Math.floor(Math.random()*n)]}function g({separator:t=" "}={}){return e=>[...e].join(t)}function _(){return t=>[...t]}function w({wordsPerLine:t={avg:10,std:3,min:1}}={}){return e=>{let n=q(t),r="";for(let o of e)r&&(0==n--?(r+="\n",n=q(t)):r+=" "),r+=o;return r}}function b(t=[5,10]){const n="number"==typeof t?t:e(...t);return function*(t){let e=0;for(let r of t){if(e++>=n)break;yield r}}}function y({}={}){return function*(t){for(let e of t)yield z(e)}}function v({wordsPerSentence:t={avg:24,std:5,min:1},punctuation:e="."}={}){return function*(n){let r,o=0;for(let s of n)r&&(yield r),r=s,0===o&&(r=z(r),o=q(t)),0==--o&&(r+=e);r&&(r.endsWith(e)||(r+=e),yield r)}}function z(t){return t[0].toUpperCase()+t.substring(1)}function q(t){if("number"==typeof t)return Math.round(e);let{avg:e,std:n,min:r,max:o}=t;void 0===n&&(n=e/4);let s=u()*n+e;return void 0!==r&&(s=Math.max(r,s)),void 0!==o&&(s=Math.min(o,s)),Math.round(s)}var $=Object.freeze({__proto__:null,array:_,base:h,description:v,limit:b,lorem:d,multiline:w,string:g,title:y});const M="// module\nimport { a, b } from './module';\nimport * as module from './module';\nimport module from './module';\nexport default module;\nexport const a = 0;\nexport * from './module';\nexport * as module from './module';\n\n// variables\nlet a = 10;\nconst b = 20;\n\n// function declaration\nfunction sum(x, y) {\n return x + y;\n}\n\n// generator function\nfunction* iterator() {\n yield 0;\n yield 1;\n}\n\n// arrow function\nconst multiply = (x, y) => x * y;\n\n// class\nclass Person {\n constructor(name, age) {\n this.name = name;\n this.age = age;\n }\n\n greet() {\n console.log('Hello, my name is Miso.');\n }\n}\n\n// primitive\nconst str = 'Hello, world!';\nconst num = 10.99;\n\n// object\nconst person = new Person('John', 30);\nperson.greet();\n\n// object literal\nconst object = {\n name: 'John',\n [x]: 10,\n ...props,\n};\n\n// array literal\nconst arr = [1, 2, 3, 4, 5, ...props];\n\n// regexp literal\nconst regexp = /\\w+/g;\n\n// operators\nconst sum = a + b;\nconst product = a * b;\nconst negation = -a;\nconst max = a > b ? a : b;\n\n// flow control\nlet i = 9;\nfor (const n of arr) {\n if (n > i) {\n console.log(n);\n }\n i++;\n}\n\n// async/await\n(async () => {\n const result = await asyncFunction();\n})();\n\n// try/catch\ntry {\n} catch (e) {\n}\n\n// destructuring\nconst { name, age, ...rest } = person;\nconst [ x, y, ...rest ] = arr;\n\n// template literals\nconsole.log(`The sum of ${a} and ${b} is ${sum(a, b)}.`);";var x=Object.freeze({__proto__:null,javascript:function(){return M},js:function(){return M}});function j({features:t,blocks:e=[8,12],sampling:n=1}={}){let r=[];return[r,t]=function(t=[]){const e=new Set,n=[];for(const r of t)if(r.startsWith("lang-")){let t=r.slice(5);"javascript"===t&&(t="js"),e.add(t)}else n.push(r);return[[...e],n]}(t),function(t,e){const n=[];for(const r of t)1>e&&Math.random()>=e||n.push(r());return n}([()=>S({features:t}),()=>A({features:t}),...r.map((e=>()=>O({lang:e,features:t}))),...r.length?[]:[()=>O({features:t})],()=>A({features:t}),()=>D({features:t}),()=>C(),()=>A({features:t}),()=>k(),()=>S({features:t}),()=>A({features:t}),()=>F({features:t}),()=>A({features:t})],n).join("\n\n")}function k(){return"*-_".charAt(e(0,2)).repeat(e(3,6))}function S({level:t=[1,6],size:n=[1,8],content:r}){const o=r||d({size:n});return`${"#".repeat(e(...t))} ${o}`}function O({lang:t,content:n,size:r,fenceChar:o="`"}){return"random"===o&&(o="`~".charAt(e(0,1))),n=n||B({lang:t,size:r}),`${o.repeat(3)}${t||""}\n${n}\n${o.repeat(3)}`}function A({size:t=[20,50]}){return d({size:t,decorates:["description",U()]})}function D({columns:t=[2,4],rows:n=[2,8]}){t=e(...t),n=e(...n);const r=[...K({size:1},t-1),{size:[3,8]}],o=[d({size:t,output:"array"}),r.map((()=>"---"))];for(let t=0;n-1>t;t++)o.push(r.map((({size:t})=>d({size:t}))));return o.map(J).join("\n")}function C({url:t,imageSize:e=[400,250],...n}={}){return t=t||s(e),`![${E(n)}](${t})`}const T=["ordered","bullet","task"];function F({features:t,type:n="random",count:r=[1,8],size:o=[5,15]}){r="number"==typeof r?r:e(...r);const s="random"===n?T[Math.floor(3*Math.random())]:n,i=[];for(;r>0;){const a=e(1,r);let u=A({features:t,size:o});a>1&&(u+="\n"+F({features:t,type:n,count:a-1,size:o})),i.push(W(s,u)),r-=a}return i.join("\n")}const I={"code-span":()=>["`","`"],"emphasis-1":()=>K(H(1),2),"emphasis-2":()=>K(H(2),2),"emphasis-3":()=>K(H(3),2),strikethrough:()=>["~","~"],link:({url:t="https://miso.ai"}={})=>["[",`](${t})`]};function H(t=[1,3]){return t="number"==typeof t?t:e(...t),"_*".charAt(e(0,1)).repeat(t)}const L=Object.keys(I),P=new Set(L);function U({features:t=L,size:n=[1,3],rest:r=[0,8]}={}){t=t.filter((t=>P.has(t)));const s=o([...t]);let i=s.length-1;const a=()=>"number"==typeof r?r:e(...r);return function*(r){let o,u,c=a();for(const l of r)if(u&&(yield u),0===c)if(o)u=`${l}${o}`,o=void 0,c=a();else{const[r,a]=I[0>i?t[e(0,t.length-1)]:s[i--]]();u=`${r}${l}`,o=a,c="number"==typeof n?n:e(...n)}else u=l,c--;u&&(yield void 0!==o?`${u}${o}`:u)}}function E({size:t=[1,3],content:e}={}){return e||d({size:t})}function R(t,e){return e.split("\n").map((e=>" ".repeat(t)+e)).join("\n")}function W(t,e){const[n,r]=e.split("\n",2),o=`${function(t,e="random"){switch(t){case"ordered":return"1.";case"bullet":return"-";case"task":return`- [${("random"===e?.5>Math.random():e)?"x":" "}]`;default:throw Error("unknown list item type: "+t)}}(t)} ${n}`;return r?o+"\n"+R("ordered"===t?3:2,r):o}function B({lang:t,size:e=[10,30]}){return t&&x[t]?x[t]():d({output:"multiline",size:e})}function J(t){return`| ${t.join(" | ")} |`}function K(t,e){const n=[];for(let r=0;e>r;r++)n.push("function"==typeof t?t():t);return n}var G=Object.freeze({__proto__:null,atxHeading:S,blockquote:function({size:t=[3,5]}){return d({size:t}).split("\n").map((t=>"> "+t)).join("\n")},codeSpan:function(t){return`\`${E(t)}\``},decorate:U,emphasis:function({level:t=[1,3],options:n}){t="number"==typeof t?t:e(...t);const r="_*".charAt(e(0,1)).repeat(t);return`${r}${E(n)}${r}`},fencedCodeBlock:O,hr:k,image:C,indent:R,indentedCodeBlock:function({lang:t,content:e,size:n}){return R(4,e=e||B({lang:t,size:n}))},link:function({url:t="https://miso.ai",...e}={}){return`[${E(e)}](${t})`},linkReferenceDefinition:function({label:t,destination:e,title:n}){return`[${t}]: ${e}${void 0!==n?" "+n:""}`},list:F,listItem:W,markdown:j,paragraph:A,setextHeading:function({level:t=[1,2],size:n=[1,8],content:r}){return`${r||d({size:n})}\n${"=-".charAt(e(...t)-1).repeat(3)}`},table:D});const N=864e5,Q=7*N;function V({}={}){const t=Date.now()-N,e=t-8*Q;return new Date(e+Math.random()*(t-e)).toISOString()}function Z({size:t=300}={}){return s(t)}function X({size:t=[1,3]}={}){return d({size:t,decorates:["title"],output:"array"})}function Y({size:t=[1,4]}={}){return d({size:t,output:"array"})}function tt({size:t=[2,6]}={}){return d({size:t,decorates:["title"]})}function et({size:t=[10,20],...e}={}){return d({size:t,decorates:[Object.keys(e).length?["description",e]:"description"]})}function nt({paragraphs:t=8,sections:e,paragraph:n,image:r}={}){n={size:[30,60],...n},r={size:[480,270],...r},void 0===e&&(e=Math.floor(t*(1+Math.random())/4));const o=[],s=t/(e=Math.max(1,Math.min(e,t)));let i=0;for(let t=0;e>t;t++){for(t>0&&o.push(`<h4>${tt()}</h4>`);i++<(t+1)*s;)o.push(`<p>${et(n)}</p>`);o.push(`<div class="image-container"><img src="${Z(r)}"></div>`)}return o.join("")}function rt(){return Math.random()>.3?"IN_STOCK":"OUT_OF_STOCK"}function ot(){return Math.floor(1e4*Math.random())/100}function st(){return Math.floor(500*Math.random())/100+1}function it({format:t,sampling:e,features:n}){return"markdown"===t?j({sampling:e,features:n}):d({min:a(50,e),max:a(50,e),decorates:["description"]})}var at=Object.freeze({__proto__:null,answer:it,authors:X,availability:rt,date:V,description:et,html:nt,image:Z,price:ot,rating:st,tags:Y,title:tt});function*ut({rows:t,...e}={}){for(let n=0;t>n;n++)yield ct({...e,index:n})}function ct({}={}){const t=r(),e=n(ot,[1,2]);return e.sort(),{product_id:t,authors:X(),categories:[],tags:Y(),title:tt(),description:et(),cover_image:Z(),url:"https://dummy.miso.ai/products/"+t,sale_price:e[0],original_price:e[e.length-1],rating:st(),availability:rt()}}const lt=new Set(["cover_image","url","created_at","updated_at","published_at"]);function*ft({rows:t,...e}={}){for(let n=0;t>n;n++)yield dt({...e,index:n})}function dt({html:t,fl:e=[]}={}){const n={product_id:r(),authors:X(),categories:[],tags:Y(),title:tt({size:[4,10]}),snippet:et({size:[20,40]}),html:nt(t)};for(const t of e)lt.has(t)&&(n[t]=mt(n,t));return n}function mt({id:t},e){switch(e){case"cover_image":return Z();case"url":return"/products/"+t;case"created_at":case"updated_at":case"published_at":return V()}}function*pt({rows:t=5,...e}={}){for(let n=0;t>n;n++)yield ht({...e,index:n})}function ht({}={}){return et({size:[4,8],punctuation:"?"})}function gt({question:e,parent_question_id:n,source_fl:r=["cover_image","url"],related_resource_fl:o=["cover_image","url"],timestamp:s=Date.now()},{answerFormat:a="markdown",answerSampling:u,answerLanguages:c=[]}={}){const l=t(),f=i(s),d=void 0!==u?Math.max(0,Math.min(1,u)):void 0,m=it({format:a,sampling:d,features:c.length?c.map((t=>"lang-"+t)):void 0}),p=[...ft({rows:_t(6,8,d),fl:o})].map(wt);return{question:e,question_id:l,...n&&{parent_question_id:n},datetime:f,answer:m,sources:[...ft({rows:_t(4,6,d),fl:r})].map(wt),related_resources:p,followup_questions:[...pt({rows:_t(3,6)})]}}function _t(t,n,r){return e(a(t,r),a(n,r))}function wt({html:t,...e}){return e}var bt=Object.freeze({__proto__:null,answer:gt,articles:ft,fields:at,lorem:$,md:G,products:ut,questions:pt,utils:l});const yt=[{name:"fetch",duration:1.5,text:"Checking the question and fetching results... "},{name:"verify",duration:1.5,text:"Verifying results... "},{name:"generate",duration:1.5,text:"Generating answer... "}];class vt{constructor(t={}){this._options=t,this._answers=new Map}questions(t,e={}){const n=new zt(t,{...this._options,...e}),{question_id:r}=n;return this._answers.set(r,n),{question_id:r}}answer(t){const e=this._answers.get(t);if(!e){const e=Error("Question not found: "+t);throw e.status=404,e}return e.get()}related_questions(t){return{related_questions:[...pt(t)]}}}class zt{constructor(t,{answerFormat:e,answerSampling:n,answerLanguages:r,...o}={}){this._options=Object.freeze(o);const s=this.timestamp=Date.now();this._data=gt({...t,timestamp:s},{answerFormat:e,answerSampling:n,answerLanguages:r})}get question_id(){return this._data.question_id}get(){const t=(Date.now()-this.timestamp)*(this._options.speedRate||1)/1e3,[e,n,r]=this._answer(t),o=this._sources(t,r),s=this._related_resources(t,r),i=this._followup_questions(t,r),{question_id:a,question:u,datetime:c,parent_question_id:l}=this._data;return{answer:n,answer_stage:e,datetime:c,finished:r,parent_question_id:l,question:u,question_id:a,sources:o,related_resources:s,followup_questions:i}}_answer(t){for(const e of yt)if(0>(t-=e.duration))return[e.name,e.text,!1];const{answer:e}=this._data,n=Math.floor(100*t),r=n>=e.length;return["result",r?e:e.slice(0,n),r]}_sources(t,e){const{sources:n}=this._data;if(e)return n;const{length:r}=n;return n.slice(0,Math.floor(r*t/3))}_related_resources(t,e){const{related_resources:n}=this._data;if(e)return n;const{length:r}=n;return n.slice(0,Math.floor(r*t/3))}_followup_questions(t,e){const{followup_questions:n}=this._data;if(e||!n)return n;const{length:r}=n;return n.slice(0,Math.floor(r*t/3))}}class qt{constructor(t){this._options=t}search({rows:t=5}){return{products:[...ut({rows:t})]}}}class $t{constructor(t){this._options=t}user_to_products({rows:t=5}){return{products:[...ut({rows:t})]}}product_to_products({rows:t=5}){return{products:[...ut({rows:t})]}}}class Mt{constructor(t){this._options=t}upload(t){return[]}}class xt{constructor(t){this._options=t}upload(t){return[]}ids(){const t=[];for(let e=0;5e3>e;e++)t.push(jt(e));return{ids:t}}}function jt(t){return`${10>t?"p_000":100>t?"p_00":1e3>t?"p_0":"p_"}${t}`}class kt{constructor(t){this.ask=new vt(t),this.search=new qt(t),this.recommendation=new $t(t),this.interactions=new Mt(t),this.products=new xt(t)}}return{buildApi:(...t)=>new kt(...t),data:bt}}));
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@miso.ai/doggoganger",
3
- "version": "0.9.1-beta.12",
3
+ "version": "0.9.1-beta.13",
4
4
  "description": "A dummy miso endpoint for demo and testing",
5
5
  "type": "module",
6
6
  "bin": {
package/src/api/ask.js CHANGED
@@ -54,10 +54,10 @@ export default class Ask {
54
54
 
55
55
  class Answer {
56
56
 
57
- constructor({ question, parent_question_id }, { answerFormat, answerSampling, answerLanguages, ...options } = {}) {
57
+ constructor(payload, { answerFormat, answerSampling, answerLanguages, ...options } = {}) {
58
58
  this._options = Object.freeze(options);
59
59
  const timestamp = this.timestamp = Date.now();
60
- this._data = answer({ question, parent_question_id, timestamp }, { answerFormat, answerSampling, answerLanguages });
60
+ this._data = answer({ ...payload, timestamp }, { answerFormat, answerSampling, answerLanguages });
61
61
  }
62
62
 
63
63
  get question_id() {
@@ -3,7 +3,13 @@ import * as fields from './fields.js';
3
3
  import { articles } from './articles.js';
4
4
  import { questions } from './questions.js';
5
5
 
6
- export function answer({ question, parent_question_id, timestamp = Date.now() }, { answerFormat = 'markdown', answerSampling, answerLanguages = [] } = {}) {
6
+ export function answer({
7
+ question,
8
+ parent_question_id,
9
+ source_fl = ['cover_image', 'url'],
10
+ related_resource_fl = ['cover_image', 'url'],
11
+ timestamp = Date.now(),
12
+ }, { answerFormat = 'markdown', answerSampling, answerLanguages = [] } = {}) {
7
13
 
8
14
  const question_id = uuid();
9
15
  const datetime = formatDatetime(timestamp);
@@ -12,8 +18,8 @@ export function answer({ question, parent_question_id, timestamp = Date.now() },
12
18
  const features = answerLanguages.length ? answerLanguages.map(language => `lang-${language}`) : undefined;
13
19
 
14
20
  const answer = fields.answer({ format: answerFormat, sampling, features });
15
- const related_resources = [...articles({ rows: sampleRandomInt(6, 8, sampling) })].map(excludeHtml);
16
- const sources = [...articles({ rows: sampleRandomInt(4, 6, sampling) })].map(excludeHtml);
21
+ const related_resources = [...articles({ rows: sampleRandomInt(6, 8, sampling), fl: related_resource_fl })].map(excludeHtml);
22
+ const sources = [...articles({ rows: sampleRandomInt(4, 6, sampling), fl: source_fl })].map(excludeHtml);
17
23
  const followup_questions = [...questions({ rows: sampleRandomInt(3, 6) })];
18
24
 
19
25
  return {
@@ -1,16 +1,24 @@
1
1
  import * as u from './utils.js';
2
2
  import * as fields from './fields.js';
3
3
 
4
+ const FIELDS = new Set([
5
+ 'cover_image',
6
+ 'url',
7
+ 'created_at',
8
+ 'updated_at',
9
+ 'published_at',
10
+ ]);
11
+
4
12
  export function *articles({ rows, ...options } = {}) {
5
13
  for (let i = 0; i < rows; i++) {
6
14
  yield article({ ...options, index: i });
7
15
  }
8
16
  }
9
17
 
10
- function article({ html } = {}) {
18
+ function article({ html, fl = [] } = {}) {
11
19
  const id = u.id();
12
20
 
13
- return {
21
+ const article = {
14
22
  product_id: id,
15
23
  authors: fields.authors(),
16
24
  categories: [],
@@ -18,7 +26,26 @@ function article({ html } = {}) {
18
26
  title: fields.title({ size: [4, 10] }),
19
27
  snippet: fields.description({ size: [20, 40] }),
20
28
  html: fields.html(html),
21
- cover_image: fields.image(),
22
- url: `/products/${id}`,
23
29
  };
30
+
31
+ for (const field of fl) {
32
+ if (FIELDS.has(field)) {
33
+ article[field] = property(article, field);
34
+ }
35
+ }
36
+
37
+ return article;
38
+ }
39
+
40
+ function property({ id }, field) {
41
+ switch (field) {
42
+ case 'cover_image':
43
+ return fields.image();
44
+ case 'url':
45
+ return `/products/${id}`;
46
+ case 'created_at':
47
+ case 'updated_at':
48
+ case 'published_at':
49
+ return fields.date();
50
+ }
24
51
  }
@@ -2,6 +2,16 @@ import * as lorem from './lorem.js';
2
2
  import { imageUrl, sample } from './utils.js';
3
3
  import * as md from './markdown/index.js';
4
4
 
5
+ const DAY = 1000 * 60 * 60 * 24;
6
+ const WEEK = DAY * 7;
7
+
8
+ export function date({} = {}) {
9
+ const now = Date.now();
10
+ const max = now - DAY;
11
+ const min = max - WEEK * 8;
12
+ return new Date(min + Math.random() * (max - min)).toISOString();
13
+ }
14
+
5
15
  export function image({ size = 300 } = {}) {
6
16
  return imageUrl(size);
7
17
  }